﻿// ***************************************************************
//  dynamic_class   version:  1.0   ·  date: 05/29/2010
//  -------------------------------------------------------------
//  抽象的动态PE(Property & Event)类型，作为所有需要动态PE特性的类型的功能基类。
//  -------------------------------------------------------------
//  Copyright (C) 2010 - All Rights Reserved
// ***************************************************************
// 
// ***************************************************************
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#ifndef ccs_util_class_dynamic_class_h__
#define ccs_util_class_dynamic_class_h__

#include "ccs_util/archive.hpp"
#include "ccs_util/event.hpp"

typedef int32 error_code;

namespace ccs
{
	class dynamic_class
	{
	public:
		template<typename XClass>
		event::connection observe_property(std::string const& propName, std::string const& eventName,
			void (XClass::*proc)(dynamic_class&, std::string const&, iarchive&), XClass& obj)
		{
			return props_.observe_property(propName, eventName,
				boost::bind(proc, boost::ref(obj), boost::ref(*this), _1, _2));
		}

		event::connection observe_property(std::string const& propName, std::string const& eventName,
			void (*proc)(dynamic_class&, std::string const&, iarchive&))
		{
			return props_.observe_property(propName, eventName,
				boost::bind(proc, boost::ref(*this), _1, _2));
		}

		event::connection observe_property(std::string const& propName,
			std::string const& eventName, event::slot2 const& handler)
		{
			return props_.observe_property(propName, eventName, handler);
		}

		template<typename VarType>
		property const& add_property(std::string const& propName, VarType const& var)
		{
			return props_.add_property(propName, var);
		}

		template<typename VarType>
		void set_property(std::string const& propName, VarType const& var)
		{
			props_.set_property(propName, var);
		}

		property const& get_property(std::string const& propName) const
		{
			return props_.get_property(propName);
		}

	public:

		property_set props_;
	};

}

#endif /*ccs_util_class_dynamic_class_h__*/